package com.wisewin.pose.dao;

import com.wisewin.pose.entity.db.UserPhysicalActionTrendDO;
import com.wisewin.pose.entity.db.UserPhysicalRecordDO;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserPhysicalActionTrendDAO {

        @Select("SELECT r.record_id, a.action_id, a.action_name, a.max_neck_degree, a.max_side_bend_angle, a.shoulder_right_angle, a.shoulder_left_angle, a.torso_angle, a.min_hip_right_angle, a.min_hip_left_angle, a.min_leg_right_angle, a.min_leg_left_angle, a.max_hip_right_angle, a.max_hip_left_angle "
                        +
                        "FROM yoga_pose.tb_user_physical_record r " +
                        "LEFT JOIN yoga_pose.tb_user_physical_action a ON r.record_id = a.record_id " +
                        "JOIN (SELECT record_id, user_id FROM yoga_pose.tb_user_physical_record WHERE user_id = #{userId} and record_id <= #{recordId} ORDER BY record_id DESC LIMIT 5) AS recent_records ON r.record_id = recent_records.record_id "
                        +
                        "ORDER BY r.record_id DESC, a.action_id " +
                        "LIMIT 0, 1000")
        List<UserPhysicalActionTrendDO> getUserPhysicalActionTrendsByUserId(@Param("userId") Integer userId,
                        @Param("recordId") Integer recordId);

        @Select("SELECT record_id, user_id, create_time, motion_range_score, stability_score, symmetry_score, overall_score, neck_risk_value, hips_risk_value, legs_risk_value,  overall_risk_score FROM yoga_pose.tb_user_physical_record WHERE user_id = #{userId} and record_id <= #{recordId} ORDER BY record_id DESC LIMIT 5")
        List<UserPhysicalRecordDO> getRecordsDates(@Param("userId") Integer userId,
                        @Param("recordId") Integer recordId);
}